<?php
class FichierAppelOffreController extends Controller{
	
	public $id_fichier;
	public $nom_secondaire;
	public $chemin;
	
	public function index(){
		if(!isset($_SESSION['email'])){
			$this->redirect(SITE.'/#popup_connexion');	
		}
		$model = $this->loadModel('AppelOffreManager');
		if(empty($this->request->params)){
			$this->render('/404.php');	
		}
		if(count($this->request->params)==2){
			$id = intval($this->request->params[0]);
			$nom_secondaire = $this->request->params[1];
			if($nom_secondaire!='fournisseur.pdf'){
				$this->render('/404.php');	
			} else if(! $model->appelOffreFournisseurExiste($id,$_SESSION['id_utilisateur'])){
				$this->render('/404.php');
			} else {
				$this->id_fichier = $id;
				$this->nom_secondaire = $nom_secondaire;
				$this->chemin = WEBROOT.DS.'fichier_appel_offre'.DS.$id.$nom_secondaire;
			}
		} else if(count($this->request->params)==1){
			$id = intval($this->request->params[0]);
		} else {
			
		}
	}
	
	public function renderPDF($action){
		
		//ob_start();
		header("Content-type: application/pdf");
		header("Content-Disposition: attachment; filename=$this->chemin");
		header("Content-Transfer-Encoding: application/pdf");
		readfile($this->chemin);
		//require_once $this->chemin;
		//$content = ob_get_clean();
	}
	public function telechargerFichier(){
		
	}
}